export default class WySong {
  constructor({
    id,
    singer,
    name,
    image,
    duration,
    url
  }) {
    this.id = id
    this.singer = singer
    this.name = name
    this.image = image
    this.url = url
    this.duration = duration
  }
}

export function createSong(musicData) {
  return new WySong({
    id: musicData.id,
    singer: filterSinger(musicData.ar) ? filterSinger(musicData.ar) : filterSinger(musicData.artists),
    name: musicData.name,
    image: musicData.al.picUrl ? musicData.al.picUrl : musicData.artists.img1v1Url,
    duration: musicData.dt ? musicData.dt : musicData.duration
  })
}

function filterSinger(singer) {
  let ret = []
  if (!singer) {
    return ''
  }
  singer.forEach((s) => {
    // console.log(s);
    ret.push(s.name)
  })
  return ret.join('/')
}

